import {
    reqAddUser
} from '../../api'
const profile = document.getElementById('profile')
const preview = document.getElementById('preview')
profile.onchange = e => {
    const file = e.target.files[0]
    const fileReader = new FileReader()
    fileReader.readAsDataURL(file)
    fileReader.onload = () => {
        preview.src = fileReader.result
    }
}

const addForm = document.getElementById('addForm')
addForm.onsubmit = async e => {
    e.preventDefault()
    const formData = new FormData(addForm)
    const result = await reqAddUser(formData)
    if (result.code == 200) {
        window.location = '/users.html'
    }
}